package cn.sunlelin.educationserver.service.Impl;

import cn.sunlelin.educationserver.entity.Authority;
import cn.sunlelin.educationserver.mapper.AuthorityMapper;
import cn.sunlelin.educationserver.service.AuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class AuthorityServiceImpl implements AuthorityService {
    @Autowired
    private AuthorityMapper authorityMapper;

    @Override
    public Boolean createAuthority(Authority authority) {
        if(this.selectAuthorityByUserId(authority.getUserId())!=null)
            return false;
        authority.setCreateTime(new Date());
        authorityMapper.createAuthority(authority);
        return true;
    }

    @Override
    public Boolean updateAuthority(Authority authority) {
        if(this.selectAuthorityByUserId(authority.getUserId())==null)
            return false;
        authority.setUpdateTime(new Date());
        authorityMapper.updateAuthority(authority);
        return true;
    }

    @Override
    public Authority selectAuthorityByUserId(Integer userId) {
        return authorityMapper.selectAuthorityByUserId(userId);
    }

    @Override
    public Boolean deleteAuthority(Integer userId) {
        if(this.selectAuthorityByUserId(userId)==null)
            return false;
        Authority authority=new Authority();
        authority.setUserId(userId);
        authority.setUpdateTime(new Date());
        authorityMapper.deleteAuthority(authority);
        return true;
    }
}
